public class Main {
    public static int val = 0;
    public static void main(String[] args) throws InterruptedException {
        Object object = new Object();
        Thread[] t = new Thread[20];
        for(int i = 0; i < 20; i++){
            t[i] = new Thread(() -> {
                synchronized (object){
                    System.out.print(val + " ");
                    val++;
                }
            });
        }
        for(int i = 0; i < 20; i++){
            t[i].start();
        }
        for(int i = 0; i < 20; i++){
            t[i].join();
        }
        System.out.println("ok");
    }
}